package org.example.myspring02.SqlMapper;

import org.springframework.stereotype.Component;

import java.sql.*;
@Component
public class SQLconnect {
    private String url="jdbc:mysql://localhost:3306/mydb";
    private String username="root";
    private String password="123456";

    private static String driver="com.mysql.cj.jdbc.Driver";
    static {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    public Connection getConnection() throws SQLException {
        return DriverManager.getConnection(url,username,password);
    }
    public void close(Connection conn, PreparedStatement pstmt, ResultSet rs ) throws SQLException {
        if(rs!=null)
            rs.close();
        if(pstmt!=null)
            pstmt.close();
        if(conn!=null)
            conn.close();
    }
}
